package com.example.controller;

import com.example.common.Result;
import com.example.entity.Goodsorders;
import com.example.service.GoodsordersService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/goodsorders")
public class GoodsordersController {

    @Resource
    private GoodsordersService goodsordersService;

    @PostMapping("/add")
    public Result add(@RequestBody Goodsorders goodsorders) {
        goodsordersService.add(goodsorders);
        return Result.success();
    }

    @PutMapping("/update")
    public Result update(@RequestBody Goodsorders goodsorders) {
        goodsordersService.update(goodsorders);
        return Result.success();
    }

    @DeleteMapping("/deleteById/{id}")
    public Result delete(@PathVariable Integer id) {
        goodsordersService.deleteById(id);
        return Result.success();
    }

    @GetMapping("/selectAll")
    public Result selectAll(Goodsorders goodsorders) {
        List<Goodsorders> list = goodsordersService.selectAll(goodsorders);
        return Result.success(list);
    }

    @GetMapping("/selectPage")
    public Result selectPage(@RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "5") Integer pageSize,
                             Goodsorders goodsorders) {
        PageInfo<Goodsorders> info = goodsordersService.selectPage(pageNum, pageSize, goodsorders);
        return Result.success(info);
    }
}
